<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>莫伊の测试笔记</title><meta name="author" content="莫伊"><meta name="copyright" content="莫伊"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="幸运交给锦鲤，你只管努力就好">
<meta property="og:type" content="website">
<meta property="og:title" content="莫伊の测试笔记">
<meta property="og:url" content="https://mooii.gitee.io/page/2/index.html">
<meta property="og:site_name" content="莫伊の测试笔记">
<meta property="og:description" content="幸运交给锦鲤，你只管努力就好">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100">
<meta property="article:author" content="莫伊">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100"><link rel="shortcut icon" href="https://mooii.oss-cn-shanghai.aliyuncs.com/%E3%83%AA%E3%82%B9%E3%81%AE%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3%E3%81%A7%E3%81%99%E3%81%9F%E3%81%84%E3%80%82.png"><link rel="canonical" href="https://mooii.gitee.io/page/2/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '莫伊の测试笔记',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2022-05-26 16:00:46'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiperstyle.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.min.css" media="defer" onload="this.media='all'"><script async src="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus@latest/lib/carousel-touch.min.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">35</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('https://mooii.oss-cn-shanghai.aliyuncs.com/20211021164956.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">莫伊の测试笔记</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">莫伊の测试笔记</h1><div id="site-subtitle"><span id="subtitle"></span></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/12/16/selenium06/"><div class="article-content-text">input上传先定位input标签，后使用send_keys(文件地址)上传文件即可
123456def test_upload_file(self):    self.driver.get(&quot;https://image.baidu.com/&quot;)    self.driver.find_element_by_xpath(&quot;//*[@id=&#x27;sttb&#x27;]/img[1]&quot;).click()    time.sleep(2)    self.driver.find_element_by_id(&quot;stfile&quot;).send_keys(&quot;D:/users/王甜甜/图片/Saved Pictures/头像/3.JPG&quot;)    time.sleep(4)
弹框处理弹框类型：

警告框



确认框



对话框


🎃ATTENTION：

可在浏览器控制台通过window.alert(&quot;警告框&quot;)、window.confirm(&quot;确认框&quot;)、window. ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/16/selenium06/"><div class="article-title-link">selenium系列06-文件上传及弹框处理</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-16T15:23:14.000Z" title="发表于 2021-12-16 23:23:14">2021-12-16</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Selenium/">Selenium</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5373(20211213-233042).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/12/15/selenium03/"><div class="article-content-text">常用方法点击1driver.find_element_by_css_selector(&quot;#su&quot;).click()
输入/清空内容12345ele_input = driver.find_element_by_css_selector(&quot;#kw&quot;)# 输入ele_input.send_keys(&quot;selenium测试&quot;)# 清空ele_input.clear()
获取元素尺寸、坐标12345ele_input = driver.find_element_by_css_selector(&quot;#kw&quot;)# 获取元素尺寸（宽、高）size = ele_input.size# 获取元素坐标（x，y）location = ele_input.location
🍘 ATTENTION：

元素坐标值是从元素左上角和浏览器内容区域左上角来定的
返回的都是字典类型

获取元素文本123btn = driver.find_element_by_css_selector(&quot;#su&quot;)# 获取元素文本信息bt ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/15/selenium03/"><div class="article-title-link">selenium系列03-web控件交互</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-15T15:23:14.000Z" title="发表于 2021-12-15 23:23:14">2021-12-15</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Selenium/">Selenium</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5372(20211213-233028).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/12/15/selenium04/"><div class="article-content-text">设置元素等待的原因
加载网页时，元素的加载速度受到网络波动影响较大，在圆度定位时，有可能网页加载出来了但是页面元素未加载出来，这时会导致元素定位失败，进而报错

加入元素等待的目的：等元素加载出来之后再去进行定位操作，可以避免报错


强制等待python自带的等待方法，time.sleep(5)强制等待，线程休眠一定时间
缺点：若指定时间较长，即使元素加载出来了，也需要等待指定时间（造成大量时间浪费）
隐式等待原理：设置一个等待的时间，轮询（默认0.5秒）查找元素是否出现，如果没出现就抛出异常
12# 在30秒内轮询查找元素，30秒后元素未出现跑异常self.driver.implicity_wait(30)
缺点：隐式等待是全局的（作用于所有的find_element方法），需要等待整个页面加载完成，才会执行下一步，会增加不必要的等待时间，不够灵活
显式等待原理：定义等待条件，当条件发生时（例如某个元素出现或某个元素可点击）继续执行操作，否则继续等待轮询查找（默认0.5s），直到超过设定的最长等待时间后抛异常（简单来说，就是直到元素出现才去操作，若超时则抛异常）
WebDriver ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/15/selenium04/"><div class="article-title-link">selenium系列04-隐式等待与显示等待</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-15T15:23:14.000Z" title="发表于 2021-12-15 23:23:14">2021-12-15</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Selenium/">Selenium</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/12/14/selenium02/"><div class="article-content-text">访问URL访问URL可通过driver.get()方式
12# 打开百度页面driver.get(&quot;https://www.baidu.com/&quot;)
前进、后退、刷新提供了back() forward() refresh()方法，可实现浏览器网页之间的后退和前进
123456# 页面回退driver.back()# 页面前进driver.forward()# 页面刷新driver.refresh()
控制浏览器窗口大小selenium可将浏览器设置成想要的大小、位置等
123456789101112131415# 设置大小，参数为数字，表示窗口像素大小driver.set_window_size(520, 520)# 设置窗口坐标driver.set_window_position(30,30)# 可同时设置窗口大小、位置等driver.set_window_rect(40,80,400,800)# 控制浏览器窗口最大化driver.maximize_window()#获取窗口大小driver.get_window_size()#获取当前窗口坐标driver.get ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/14/selenium02/"><div class="article-title-link">selenium系列02-控制浏览器常用操作</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-14T15:24:14.000Z" title="发表于 2021-12-14 23:24:14">2021-12-14</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Selenium/">Selenium</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5373(20211213-233042).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/12/14/selenium01/"><div class="article-content-text">
以我们万能的百度页面为例来展开！

ID12# 找到搜索框inputele = driver.find_element_by_id(&quot;kw&quot;)
⏰ ATTENTION：一般来说，ID是唯一的（但是不排除这种情况——开发写代码的时候不规范🤣）
CLASS12345678# 通过class查找元素，返回匹配到的第一个元素# 搜索框inputele = driver.find_element_by_class_name(&quot;s_ipt&quot;)# 假如页面上存在多个class为s_ipt的元素则可用以下方式input_list = driver.find_elements_by_class_name(&quot;s_ipt&quot;)for i in input_list:    print(i)
⏰ ATTENTION：

一般而言，class不唯一
find_element_by_class_name 只返回匹配到的第一个class元素，找不到元素会报错

find_elements_by_class_name 返回所有匹配到的元素列表，找不到元素会 ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/14/selenium01/"><div class="article-title-link">selenium系列01-定位方式</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-14T15:23:14.000Z" title="发表于 2021-12-14 23:23:14">2021-12-14</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Selenium/">Selenium</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5372(20211213-233028).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/12/13/pytest20/"><div class="article-content-text"></div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/13/pytest20/"><div class="article-title-link">pytest20</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-13T15:23:14.000Z" title="发表于 2021-12-13 23:23:14">2021-12-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5375(20211213-233124).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/12/13/pytest19/"><div class="article-content-text">使用场景
用例修改名称之后，重新运行用例并且生成报告，会保留上一次的用例运行记录
分别运行不同的用例文件，如果生成报告的目录是同一个，那么在运行不同的用例文件之后，生成的报告会同时显示两个用例文件的运行情况

使用方法首先看下pytest提供的的报告相关的三个参数pytest -h
1234reporting:  --alluredir=DIR       Generate Allure report in the specified directory (may not exist)  --clean-alluredir     Clean alluredir folder if it exists  --allure-no-capture   Do not attach pytest captured logging/stdout/stderr to report
运行时在命令行参数中使用--clean-alluredir参数，可清空报告生成的目录
12pytest -vs .\TestFixture.py --alluredir=./result --clean-alluredi ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/13/pytest19/"><div class="article-title-link">Pytest系列19-allure清除历史记录</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-13T15:22:53.000Z" title="发表于 2021-12-13 23:22:53">2021-12-13</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/12/09/pytest18/"><div class="article-content-text">前言
一般在执行UI自动化的过程中，经常会遇到用例执行失败的情形，可以在用例执行失败的时候截图，并将截图添加至报告中，方便排查问题
解决方法：allure.attach即可实现

allure.attach使用
@allure.attach()可以添加图片或者HTML

 使用方法 
              
              在测试报告中附加网页123allure.attach(body(内容),name,attachment_type,extension)# 例如allure.attach(&#x27;&lt;head&gt;&lt;/head&gt;&lt;body&gt;首页&lt;/body&gt;&#x27;,&#x27;这是错误页的信息&#x27;,allure.attachment_type.HTML)在测试报告中附加图片123allure.attach.file(source,name,attachment_type,extension)# 例如allure.attach.file(&#x27;./result/test.png&#x27;,attach ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/09/pytest18/"><div class="article-title-link">Pytest系列18-测试报告中添加截图</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-08T16:26:59.000Z" title="发表于 2021-12-09 00:26:59">2021-12-09</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5373(20211213-233042).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/12/09/pytest17/"><div class="article-content-text">前言
使用场景：通常测试有P0、冒烟测试、验证上线测试，可以按照重要性级别来分别执行

实现方式
方法一：通过附加pytest.mark标记实现
方法二：通过allure.feature()、allure.story()实现
方法三：通过allure.severity()附加标记实现

等级介绍severity提供的级别
12345Blocker：中断级别（客户端程序无响应）critical：临界缺陷（功能点缺失）normal：普通缺陷（边界情况，格式错误）minor：次要缺陷（界面错误与ui需求不符）trivial： 轻微缺陷（必须项无提示，或者提示不规范）
使用方式
在方法、函数、类上添加@allure.severity(allure.severity_level.BLOCKER)即可

123@allure.severity(allure.severity_level.BLOCKER)def test_with_severity_blocker(self):    pass
执行方式1pytest -sv 文件名 --alluredir=./result --allure-sev ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/09/pytest17/"><div class="article-title-link">Pytest系列17-添加用例级别</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-08T16:26:24.000Z" title="发表于 2021-12-09 00:26:24">2021-12-09</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/12/07/pytest16/"><div class="article-content-text">前言首先，我们来看下三者的源码
linkissuetestcase12def link(url, link_type=LinkType.LINK, name=None):    return safely(plugin_manager.hook.decorate_as_link(url=url, link_type=link_type, name=name))12def issue(url, name=None):    return link(url, link_type=LinkType.ISSUE, name=name)12def testcase(url, name=None):    return link(url, link_type=LinkType.TEST_CASE, name=name)

🎂 ATTENTION：


从源码可以看出，issue和testcase调用的其实都是link，只是link_type不一样
url（跳转链接）必传
name（可选参数，建议传）显示在报告中的名称

示例 小栗子 
              
              源 ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/07/pytest16/"><div class="article-title-link">Pytest系列16-allure特性link、issue、testcase使用说明</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-06T16:15:44.000Z" title="发表于 2021-12-07 00:15:44">2021-12-07</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5373(20211213-233042).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/#content-inner">3</a><a class="page-number" href="/page/4/#content-inner">4</a><a class="extend next" rel="next" href="/page/3/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">莫伊</div><div class="author-info__description">幸运交给锦鲤，你只管努力就好</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">35</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/mooii"><i class="https://mooii.oss-cn-shanghai.aliyuncs.com/20211021164956.png"></i><span>我的主页</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">人生有限，接受事与愿违！！！</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/05/25/python06/" title="python06-输入与输出"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5373(20211213-233042).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python06-输入与输出"/></a><div class="content"><a class="title" href="/2022/05/25/python06/" title="python06-输入与输出">python06-输入与输出</a><time datetime="2022-05-25T14:40:00.000Z" title="发表于 2022-05-25 22:40:00">2022-05-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/05/25/python05/" title="python05-字典和集合"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python05-字典和集合"/></a><div class="content"><a class="title" href="/2022/05/25/python05/" title="python05-字典和集合">python05-字典和集合</a><time datetime="2022-05-25T14:20:14.000Z" title="发表于 2022-05-25 22:20:14">2022-05-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/04/10/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%9501/" title="性能测试01-性能测试中各种指标的关系"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="性能测试01-性能测试中各种指标的关系"/></a><div class="content"><a class="title" href="/2022/04/10/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%9501/" title="性能测试01-性能测试中各种指标的关系">性能测试01-性能测试中各种指标的关系</a><time datetime="2022-04-10T15:17:35.000Z" title="发表于 2022-04-10 23:17:35">2022-04-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/01/09/python04/" title="python04-文件读取"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python04-文件读取"/></a><div class="content"><a class="title" href="/2022/01/09/python04/" title="python04-文件读取">python04-文件读取</a><time datetime="2022-01-09T15:03:14.000Z" title="发表于 2022-01-09 23:03:14">2022-01-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/01/09/python03/" title="python03-字符串常用函数"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5374(20211213-233104).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python03-字符串常用函数"/></a><div class="content"><a class="title" href="/2022/01/09/python03/" title="python03-字符串常用函数">python03-字符串常用函数</a><time datetime="2022-01-09T15:02:17.000Z" title="发表于 2022-01-09 23:02:17">2022-01-09</time></div></div></div></div><div class="card-widget" id="card-newest-comments"><div class="item-headline"><i class="fas fa-comment-dots"></i><span>最新评论</span></div><div class="aside-list"><span>正在加载中...</span></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Pytest/"><span class="card-category-list-name">Pytest</span><span class="card-category-list-count">20</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Python/"><span class="card-category-list-name">Python</span><span class="card-category-list-count">6</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Selenium/"><span class="card-category-list-name">Selenium</span><span class="card-category-list-count">8</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/"><span class="card-category-list-name">性能测试</span><span class="card-category-list-count">1</span></a></li>
            </ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/Pytest/" style="font-size: 1.5em; color: #99a9bf">Pytest</a> <a href="/tags/Python/" style="font-size: 1.23em; color: #999ea6">Python</a> <a href="/tags/Selenium/" style="font-size: 1.37em; color: #99a4b2">Selenium</a> <a href="/tags/UI%E8%87%AA%E5%8A%A8%E5%8C%96/" style="font-size: 1.37em; color: #99a4b2">UI自动化</a> <a href="/tags/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/" style="font-size: 1.1em; color: #999">性能测试</a> <a href="/tags/%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6/" style="font-size: 1.5em; color: #99a9bf">测试框架</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/05/"><span class="card-archive-list-date">五月 2022</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/04/"><span class="card-archive-list-date">四月 2022</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/01/"><span class="card-archive-list-date">一月 2022</span><span class="card-archive-list-count">4</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/12/"><span class="card-archive-list-date">十二月 2021</span><span class="card-archive-list-count">14</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/11/"><span class="card-archive-list-date">十一月 2021</span><span class="card-archive-list-count">13</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/10/"><span class="card-archive-list-date">十月 2021</span><span class="card-archive-list-count">1</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">35</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2021-11-17T16:00:00.000Z"></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2022-05-26T08:00:45.808Z"></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2022 By 莫伊</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">好好学习🧡天天学习</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><div class="js-pjax"><script>function subtitleType () {
  getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => {
    jinrishici.load(function (result) {
      if (true) {
        var sub = "".length == 0 ? new Array() : "".split(',')
        var content = result.data.content
        var both = sub.unshift(content)
        var typed = new Typed('#subtitle', {
          strings: sub,
          startDelay: 300,
          typeSpeed: 150,
          loop: true,
          backSpeed: 50,
        })
      } else {
        document.getElementById('subtitle').innerHTML = result.data.content
      }
    })
  })
}

if (true) {
  if (typeof Typed === 'function') {
    subtitleType()
  } else {
    getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
  }
} else {
  subtitleType()
}
</script></div><script data-pjax defer src="/js/custom/fixed_card_widget.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><div id="fixedcard-dashboard"><button class="fixedcard-activebtn" type="button" title="用户信息" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-info&quot;,&quot;0&quot;)"><i class="fas fa-address-book"></i></button><button class="fixedcard-activebtn" type="button" title="电子钟" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-clock&quot;,&quot;0&quot;)"><i class="fas fa-cloud-sun"></i></button><button class="fixedcard-activebtn" type="button" title="碎碎念" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-shuo&quot;,&quot;0&quot;)"><i class="fas fa-comments"></i></button><button class="fixedcard-activebtn" type="button" title="最新文章" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-recent-post&quot;,&quot;0&quot;)"><i class="fas fa-history"></i></button><button class="fixedcard-activebtn" type="button" title="最新评论" onclick="FixedCardWidget(&quot;id&quot;,&quot;card-newest-comments&quot;,&quot;0&quot;)"><i class="fas fa-comment-dots"></i></button><button class="fixedcard-activebtn" type="button" title="标签" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-tags&quot;,&quot;0&quot;)"><i class="fas fa-tags"></i></button><button class="fixedcard-activebtn" type="button" title="网站咨询" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-webinfo&quot;,&quot;0&quot;)"><i class="fas fa-chart-line"></i></button><div class="fixedcard-user-avatar fixedcard-activebtn" onclick="RemoveFixedCardWidget()"><img class="fixedcard-user-avatar-img" src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" title="莫伊"></div></div></div><!-- hexo injector body_end start --> <script data-pjax>if(document.getElementById('recent-posts') && location.pathname =='/'){
    
    var parent = document.getElementById('recent-posts');
    var child = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms"></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载swiper')
    parent.insertAdjacentHTML("afterbegin",child)}
     </script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.js"></script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper@0.18/swiper/swiperindex.js"></script>
<style></style><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = 'undefined';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><script data-pjax>
  function butterfly_clock_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_injector_config();
  }
  </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.js"></script><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script><!-- hexo injector body_end end --></body></html>